<?php
/**
 * @var \common\models\workin\MortgageSignupHuirong $model
 */
if ($model->mortgageSignupHuirongBack) {
    $b1 = $model->mortgageSignupHuirongBack;
    $b2 = $b1->query_result;
    $b3 = json_decode($b2);
    if (!$b3) {
        $back_model = $b1;
        $client = new \yii\httpclient\Client();
        $data = [
            'grantKey' => $model->grant_key,
            'apiKey' => \common\components\increment\Config::$huirong['mortgage_signup_back_result_api_key'],
            'reportId' => $back_model->report_id,
            'plateNumber' => $back_model->plate_number,
        ];
        $response = $client->createRequest()
            ->setMethod('post')
            ->setUrl(\common\components\increment\Huirong::getUrl())
            ->setData($data)
            ->send();
        $back_model->query_result = $response->content;
        if (json_decode($back_model->query_result)){
            $back_model->save();
            $b3 = json_decode($back_model->query_result);
        }else{
            echo $b2;
            exit;
        }
    }
    $b4 = \common\components\tools\Tools::objectToArray($b3);
    $k_attr = [
        "plate_number" => "车牌号",
        "hphm" => "车牌号",
        "mortgage_tag" => "抵押标记",
//        "mortgage_owner" => "机动车所有人",
        "mortgage_owner" => "抵押权人",
        "phone" => "联系电话",
        "register_flat" => "登记住所",
        "factory_data" => "出厂日期",
//        "mortgage_date" => "初次登记日期",
        "mortgage_date" => "抵押办理日期",
        "verify_end_date" => "检验有效期止",
        "safe_end_date" => "保险终止日期",
        "is_accident_escape" => "是否事故逃逸",
        "is_cover_car" => "是否套牌车",
        "is_robbery_car" => "是否盗抢车",
        "qualified_tag_no" => "合格标志编号",
        "relieve_date" => "解除日期",
    ];
    $out = [];
    \common\components\tools\Out::bo_array($b4, $out, $k_attr);
} else {
    throw new ErrorException("没有找到关联数据", 1081);
}
?>


<div class="increment-default-civ-query-result">
    <div class="row">
        <?php if (isset($out)): ?>
            <div class="col-lg-12">
                <table class="table table-condensed table-bordered">
                    <thead>
                    <tr>
                        <th>键名</th>
                        <th>说明</th>
                        <th>值</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($out as $k => $v): ?>
                        <?php
                        $x = "";
                        for ($i = 1; $i < $v['deep']; $i++) {
                            $x .= "|--";
                        }
                        ?>
                        <tr>
                            <td width="250px"><?= $x . $v['k'] ?></td>
                            <td width="250px"><?= $v['attr'] ?></td>
                            <td><?= $v['v'] ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
        <div class="col-lg-12">
            <h6><?= $model->mortgageSignupHuirongBack->mortgage_code ?></h6>
            <h6><?= $model->mortgageSignupHuirongBack->mortgage_msg ?></h6>
        </div>
    </div>
</div>